package com.open.capacity.common.util;

public class RateUtil {
    /**
     * 将百分制转换为等级
     *
     * @param rateType 评分类型
     * @param rate     传入后台的评分数据
     * @return
     */
    public static String rateConvert(String rateType, Object rate) {
        if (rateType.equals("cent")) {
            int point = Integer.parseInt((String) rate);
            if (point >= 0 && point < 60)
                return "E";
            if (point >= 60 && point < 70)
                return "D";
            if (point >= 70 && point < 80)
                return "C";
            if (point >= 80 && point < 90)
                return "B";
            if (point >= 90 && point <= 100)
                return "A";
        }
        return (String) rate;
    }

    /**
     * 将评分转为评分等级
     *
     * @param rateTypeCode 评分类型编号
     * @param pscore 总分数
     * @return String
     */
    public static String convertPscore(String rateTypeCode, String pscore) {
        //百分制
        if (rateTypeCode.equals("cent")) {
            int point = Integer.parseInt(pscore);
            if (point >= 90 && point <= 100)
                return "优秀";
            if (point >= 80 && point < 90)
                return "良好";
            if (point >= 70 && point < 80)
                return "中等";
            if (point >= 60 && point < 70)
                return "继续努力";
            if (point >= 0 && point < 60)
                return "不及格";
        }
        //等级制
        if (rateTypeCode.equals("level")) {
            if (pscore.equals("A")){
                return "优秀";
            }
            if (pscore.equals("B")){
                return "良好";
            }
            if (pscore.equals("C")){
                return "中等";
            }
            if (pscore.equals("D")){
                return "继续努力";
            }
            if (pscore.equals("E")){
                return "不及格";
            }
        }
        //星数
        if (rateTypeCode.equals("star")) {
            int score = Integer.parseInt(pscore);
            if (score==5){
                return "优秀";
            }
            if (score==4){
                return "良好";
            }
            if (score==3){
                return "中等";
            }
            if (score==2){
                return "继续努力";
            }
            if (score==1){
                return "不及格";
            }
        }
        return null;
    }
}
